package com.neusoft.neuiotms.auth.fixture;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;

import com.neusoft.bizcore.auth.model.AuthOganization;
import com.neusoft.bizcore.auth.model.AuthRole;
import com.neusoft.bizcore.auth.model.AuthUser;
import com.neusoft.bizcore.auth.repository.AuthOganizationRepository;
import com.neusoft.bizcore.auth.repository.AuthRoleRepository;
import com.neusoft.bizcore.auth.repository.AuthUserRepository;
import com.neusoft.bizcore.auth.stress.AuthFixtureEvent;

@Profile("fixture")
@Component
public class InitialAhAuthDataFixture implements ApplicationListener<AuthFixtureEvent> {

    @Autowired
    private AuthOganizationRepository authOganizationRepository;
    @Autowired
    private AuthUserRepository authUserRepository;
    @Autowired
    private AuthRoleRepository authRoleRepository;
    @Autowired
    ApplicationContext applicationContext;

    @Override
    public void onApplicationEvent(final AuthFixtureEvent event) {
        this.init();
    }

    private void init() {

        // 顶级节点
        final AuthOganization rootOrg = this.authOganizationRepository.findByCode("root");
        if (null == rootOrg) {
            return;
        }

        // 省联社
        //        AuthOganization slOrg = this.authOganizationRepository.findByCode("sl");
        //        if (null == slOrg) {
        //            slOrg = new AuthOganization();
        //            slOrg.setCode("sl");
        //            slOrg.setName("省联社");
        //            slOrg.setParent(rootOrg);
        //            slOrg = this.authOganizationRepository.save(slOrg);
        //        }

        // 综合管理与安全保卫
        AuthOganization integratedSecurityOrg = this.authOganizationRepository.findByCode("integratedSecurity");
        if (null == integratedSecurityOrg) {
            integratedSecurityOrg = new AuthOganization();
            integratedSecurityOrg.setCode("integratedSecurity");
            integratedSecurityOrg.setName("综合管理与安全保卫");
            integratedSecurityOrg.setParent(rootOrg);
            integratedSecurityOrg = this.authOganizationRepository.save(integratedSecurityOrg);
        }

        // 电子银行
        AuthOganization eBankOrg = this.authOganizationRepository.findByCode("eBank");
        if (null == eBankOrg) {
            eBankOrg = new AuthOganization();
            eBankOrg.setCode("eBank");
            eBankOrg.setName("电子银行");
            eBankOrg.setParent(rootOrg);
            eBankOrg = this.authOganizationRepository.save(eBankOrg);
        }

        // 运行管理部
        AuthOganization runOrg = this.authOganizationRepository.findByCode("run");
        if (null == runOrg) {
            runOrg = new AuthOganization();
            runOrg.setCode("run");
            runOrg.setName("运行管理部");
            runOrg.setParent(rootOrg);
            runOrg = this.authOganizationRepository.save(runOrg);
        }

        // 机关工会
        AuthOganization laborUnionOrg = this.authOganizationRepository.findByCode("laborUnion");
        if (null == laborUnionOrg) {
            laborUnionOrg = new AuthOganization();
            laborUnionOrg.setCode("laborUnion");
            laborUnionOrg.setName("机关工会");
            laborUnionOrg.setParent(rootOrg);
            laborUnionOrg = this.authOganizationRepository.save(laborUnionOrg);
        }

        // 党风廉政办公司
        AuthOganization partyGovernmentOrg = this.authOganizationRepository.findByCode("partyGovernment");
        if (null == partyGovernmentOrg) {
            partyGovernmentOrg = new AuthOganization();
            partyGovernmentOrg.setCode("partyGovernment");
            partyGovernmentOrg.setName("党风廉政办公司");
            partyGovernmentOrg.setParent(rootOrg);
            partyGovernmentOrg = this.authOganizationRepository.save(partyGovernmentOrg);
        }

        // 财务会计部
        AuthOganization accounting = this.authOganizationRepository.findByCode("partyGovernment");
        if (null == accounting) {
            accounting = new AuthOganization();
            accounting.setCode("partyGovernment");
            accounting.setName("财务会计部");
            accounting.setParent(rootOrg);
            accounting = this.authOganizationRepository.save(accounting);
        }

        // 党群工作部
        AuthOganization partyWork = this.authOganizationRepository.findByCode("partyWork");
        if (null == partyWork) {
            partyWork = new AuthOganization();
            partyWork.setCode("partyWork");
            partyWork.setName("党群工作部");
            partyWork.setParent(rootOrg);
            partyWork = this.authOganizationRepository.save(partyWork);
        }

        // 金融市场部
        AuthOganization financialMarket = this.authOganizationRepository.findByCode("financialMarket");
        if (null == financialMarket) {
            financialMarket = new AuthOganization();
            financialMarket.setCode("financialMarket");
            financialMarket.setName("金融市场部");
            financialMarket.setParent(rootOrg);
            financialMarket = this.authOganizationRepository.save(financialMarket);
        }

        // 人力资源部
        AuthOganization hr = this.authOganizationRepository.findByCode("hr");
        if (null == hr) {
            hr = new AuthOganization();
            hr.setCode("hr");
            hr.setName("人力资源部");
            hr.setParent(rootOrg);
            hr = this.authOganizationRepository.save(hr);
        }

        // 合规与风险管理部
        AuthOganization complianceRisk = this.authOganizationRepository.findByCode("complianceRisk");
        if (null == complianceRisk) {
            complianceRisk = new AuthOganization();
            complianceRisk.setCode("complianceRisk");
            complianceRisk.setName("合规与风险管理部");
            complianceRisk.setParent(rootOrg);
            complianceRisk = this.authOganizationRepository.save(complianceRisk);
        }

        // 办公室
        AuthOganization Office = this.authOganizationRepository.findByCode("Office");
        if (null == Office) {
            Office = new AuthOganization();
            Office.setCode("Office");
            Office.setName("办公室");
            Office.setParent(rootOrg);
            Office = this.authOganizationRepository.save(Office);
        }

        // 农金学院
        AuthOganization nongJin = this.authOganizationRepository.findByCode("nongJin");
        if (null == nongJin) {
            nongJin = new AuthOganization();
            nongJin.setCode("nongJin");
            nongJin.setName("农金学院");
            nongJin.setParent(rootOrg);
            nongJin = this.authOganizationRepository.save(nongJin);
        }

        // 信贷管理部
        AuthOganization credit = this.authOganizationRepository.findByCode("credit");
        if (null == credit) {
            credit = new AuthOganization();
            credit.setCode("credit");
            credit.setName("信贷管理部");
            credit.setParent(rootOrg);
            credit = this.authOganizationRepository.save(credit);
        }

        // 审计管理部
        AuthOganization audit = this.authOganizationRepository.findByCode("audit");
        if (null == audit) {
            audit = new AuthOganization();
            audit.setCode("audit");
            audit.setName("审计管理部");
            audit.setParent(rootOrg);
            audit = this.authOganizationRepository.save(audit);
        }

        // 合肥审计中心
        AuthOganization hfAudit = this.authOganizationRepository.findByCode("hfAudit");
        if (null == hfAudit) {
            hfAudit = new AuthOganization();
            hfAudit.setCode("hfAudit");
            hfAudit.setName("合肥审计中心");
            hfAudit.setParent(rootOrg);
            hfAudit = this.authOganizationRepository.save(hfAudit);
        }

        // 反战规划与调研统计
        AuthOganization antiWar = this.authOganizationRepository.findByCode("antiWar");
        if (null == antiWar) {
            antiWar = new AuthOganization();
            antiWar.setCode("antiWar");
            antiWar.setName("反战规划与调研统计");
            antiWar.setParent(rootOrg);
            antiWar = this.authOganizationRepository.save(antiWar);
        }

        // 巡查工作办公室
        AuthOganization patrolOffice = this.authOganizationRepository.findByCode("patrolOffice");
        if (null == patrolOffice) {
            patrolOffice = new AuthOganization();
            patrolOffice.setCode("patrolOffice");
            patrolOffice.setName("巡查工作办公室");
            patrolOffice.setParent(rootOrg);
            patrolOffice = this.authOganizationRepository.save(patrolOffice);
        }

        // 业务拓展部
        AuthOganization business = this.authOganizationRepository.findByCode("business");
        if (null == business) {
            business = new AuthOganization();
            business.setCode("business");
            business.setName("业务拓展部");
            business.setParent(rootOrg);
            business = this.authOganizationRepository.save(business);
        }

        // 科技公司
        AuthOganization kjOrg = this.authOganizationRepository.findByCode("kj");
        if (null == kjOrg) {
            kjOrg = new AuthOganization();
            kjOrg.setCode("kj");
            kjOrg.setName("信息技术中心");
            kjOrg.setParent(rootOrg);
            kjOrg = this.authOganizationRepository.save(kjOrg);
        }

        // 资源保障部
        AuthOganization resProOrg = this.authOganizationRepository.findByCode("resourcesProtection");
        if (null == resProOrg) {
            resProOrg = new AuthOganization();
            resProOrg.setCode("resourcesProtection");
            resProOrg.setName("资源保障部");
            resProOrg.setParent(kjOrg);
            resProOrg = this.authOganizationRepository.save(resProOrg);
        }

        // 综合管理部
        AuthOganization comprehensiveOrg = this.authOganizationRepository.findByCode("comprehensive");
        if (null == comprehensiveOrg) {
            comprehensiveOrg = new AuthOganization();
            comprehensiveOrg.setCode("comprehensive");
            comprehensiveOrg.setName("综合管理部");
            comprehensiveOrg.setParent(kjOrg);
            comprehensiveOrg = this.authOganizationRepository.save(comprehensiveOrg);
        }

        // 科技管理部
        AuthOganization scienceTechnologyOrg = this.authOganizationRepository.findByCode("scienceTechnology");
        if (null == scienceTechnologyOrg) {
            scienceTechnologyOrg = new AuthOganization();
            scienceTechnologyOrg.setCode("scienceTechnology");
            scienceTechnologyOrg.setName("科技管理部");
            scienceTechnologyOrg.setParent(kjOrg);
            scienceTechnologyOrg = this.authOganizationRepository.save(scienceTechnologyOrg);
        }

        // 安全管理部
        AuthOganization securityOrg = this.authOganizationRepository.findByCode("security");
        if (null == securityOrg) {
            securityOrg = new AuthOganization();
            securityOrg.setCode("security");
            securityOrg.setName("安全管理部");
            securityOrg.setParent(kjOrg);
            securityOrg = this.authOganizationRepository.save(securityOrg);
        }

        // 机房管理部
        AuthOganization computerRoomOrg = this.authOganizationRepository.findByCode("computerRoom");
        if (null == computerRoomOrg) {
            computerRoomOrg = new AuthOganization();
            computerRoomOrg.setCode("computerRoom");
            computerRoomOrg.setName("机房管理部");
            computerRoomOrg.setParent(kjOrg);
            computerRoomOrg = this.authOganizationRepository.save(computerRoomOrg);
        }

        // 运行支持部
        AuthOganization operationSupportOrg = this.authOganizationRepository.findByCode("operationSupport");
        if (null == operationSupportOrg) {
            operationSupportOrg = new AuthOganization();
            operationSupportOrg.setCode("operationSupport");
            operationSupportOrg.setName("运行支持部");
            operationSupportOrg.setParent(kjOrg);
            operationSupportOrg = this.authOganizationRepository.save(operationSupportOrg);
        }

        // 应用管理部
        AuthOganization applicationOrg = this.authOganizationRepository.findByCode("application");
        if (null == applicationOrg) {
            applicationOrg = new AuthOganization();
            applicationOrg.setCode("application");
            applicationOrg.setName("应用管理部");
            applicationOrg.setParent(kjOrg);
            applicationOrg = this.authOganizationRepository.save(applicationOrg);
        }

        // 核心应用开发部
        AuthOganization coreApplicationDevelopmentOrg =
                this.authOganizationRepository.findByCode("coreApplicationDevelopment");
        if (null == coreApplicationDevelopmentOrg) {
            coreApplicationDevelopmentOrg = new AuthOganization();
            coreApplicationDevelopmentOrg.setCode("coreApplicationDevelopment");
            coreApplicationDevelopmentOrg.setName("核心应用开发部");
            coreApplicationDevelopmentOrg.setParent(kjOrg);
            coreApplicationDevelopmentOrg = this.authOganizationRepository.save(coreApplicationDevelopmentOrg);
        }

        // 渠道应用开发部
        AuthOganization channelApplicationDevelopmentOrg =
                this.authOganizationRepository.findByCode("channelApplicationDevelopment");
        if (null == channelApplicationDevelopmentOrg) {
            channelApplicationDevelopmentOrg = new AuthOganization();
            channelApplicationDevelopmentOrg.setCode("channelApplicationDevelopment");
            channelApplicationDevelopmentOrg.setName("渠道应用开发部");
            channelApplicationDevelopmentOrg.setParent(kjOrg);
            channelApplicationDevelopmentOrg = this.authOganizationRepository.save(channelApplicationDevelopmentOrg);
        }

        // 数据应用开发部
        AuthOganization dataApplicationDevelopmentOrg =
                this.authOganizationRepository.findByCode("dataApplicationDevelopment");
        if (null == dataApplicationDevelopmentOrg) {
            dataApplicationDevelopmentOrg = new AuthOganization();
            dataApplicationDevelopmentOrg.setCode("dataApplicationDevelopment");
            dataApplicationDevelopmentOrg.setName("数据应用开发部");
            dataApplicationDevelopmentOrg.setParent(kjOrg);
            dataApplicationDevelopmentOrg = this.authOganizationRepository.save(dataApplicationDevelopmentOrg);
        }

        // 需求部
        AuthOganization demandOrg =
                this.authOganizationRepository.findByCode("demand");
        if (null == demandOrg) {
            demandOrg = new AuthOganization();
            demandOrg.setCode("demand");
            demandOrg.setName("需求部");
            demandOrg.setParent(kjOrg);
            demandOrg = this.authOganizationRepository.save(dataApplicationDevelopmentOrg);
        }

        // 测试部
        AuthOganization testingOrg =
                this.authOganizationRepository.findByCode("testing");
        if (null == testingOrg) {
            testingOrg = new AuthOganization();
            testingOrg.setCode("testing");
            testingOrg.setName("测试部");
            testingOrg.setParent(kjOrg);
            testingOrg = this.authOganizationRepository.save(testingOrg);
        }

        // 研发之俩昂管理部
        AuthOganization twinChampionsOrg =
                this.authOganizationRepository.findByCode("twinChampions");
        if (null == twinChampionsOrg) {
            twinChampionsOrg = new AuthOganization();
            twinChampionsOrg.setCode("twinChampions");
            twinChampionsOrg.setName("研发之俩昂管理部");
            twinChampionsOrg.setParent(kjOrg);
            twinChampionsOrg = this.authOganizationRepository.save(twinChampionsOrg);
        }

        // 金融互联网应用开发部
        AuthOganization financialInternetOrg =
                this.authOganizationRepository.findByCode("financialInternet");
        if (null == financialInternetOrg) {
            financialInternetOrg = new AuthOganization();
            financialInternetOrg.setCode("financialInternet");
            financialInternetOrg.setName("金融互联网应用开发部");
            financialInternetOrg.setParent(kjOrg);
            financialInternetOrg = this.authOganizationRepository.save(financialInternetOrg);
        }

        // 系统管理员
        AuthRole adminRole = this.authRoleRepository.findByCode("admin");
        if (null == adminRole) {
            adminRole = new AuthRole();
            adminRole.setCode("admin");
            adminRole.setName("管理员");
            this.authRoleRepository.save(adminRole);
        }

        // 系统用户(科技公司)
        AuthRole systemUserRole = this.authRoleRepository.findByCode("kjSystemUser");
        if (null == systemUserRole) {
            systemUserRole = new AuthRole();
            systemUserRole.setCode("kjSystemUser");
            systemUserRole.setName("系统用户");
            this.authRoleRepository.save(systemUserRole);
        }

        // 部门资产专管员(科技公司)
        AuthRole kjDeptAssetAdminRole = this.authRoleRepository.findByCode("kjDeptAssetAdmin");
        if (null == kjDeptAssetAdminRole) {
            kjDeptAssetAdminRole = new AuthRole();
            kjDeptAssetAdminRole.setCode("kjDeptAssetAdmin");
            kjDeptAssetAdminRole.setName("部门资产专管员");
            this.authRoleRepository.save(kjDeptAssetAdminRole);
        }

        // 部门负责人(科技公司)
        AuthRole kjDeptPrincipalRole = this.authRoleRepository.findByCode("kjDeptPrincipal");
        if (null == kjDeptPrincipalRole) {
            kjDeptPrincipalRole = new AuthRole();
            kjDeptPrincipalRole.setCode("kjDeptPrincipal");
            kjDeptPrincipalRole.setName("部门负责人");
            this.authRoleRepository.save(kjDeptPrincipalRole);
        }

        // 资产管理员(科技公司)
        AuthRole kjAssetAdminRole = this.authRoleRepository.findByCode("kjAssetAdmin");
        if (null == kjAssetAdminRole) {
            kjAssetAdminRole = new AuthRole();
            kjAssetAdminRole.setCode("kjAssetAdmin");
            kjAssetAdminRole.setName("资产管理员");
            this.authRoleRepository.save(kjAssetAdminRole);
        }

        // 综合管理部负责人(科技公司)
        AuthRole kjAdministrationPrincipalRole = this.authRoleRepository.findByCode("kjAdministrationPrincipal");
        if (null == kjAdministrationPrincipalRole) {
            kjAdministrationPrincipalRole = new AuthRole();
            kjAdministrationPrincipalRole.setCode("kjAdministrationPrincipal");
            kjAdministrationPrincipalRole.setName("综合管理部负责人");
            this.authRoleRepository.save(kjAdministrationPrincipalRole);
        }

        // 资产采购员(省联社)
        AuthRole slAssetBuyerRole = this.authRoleRepository.findByCode("slAssetBuyer");
        if (null == slAssetBuyerRole) {
            slAssetBuyerRole = new AuthRole();
            slAssetBuyerRole.setCode("slAssetBuyer");
            slAssetBuyerRole.setName("资产采购员");
            this.authRoleRepository.save(slAssetBuyerRole);
        }

        // 部门资产管理员(省联社)
        AuthRole slDeptAssetAdminRole = this.authRoleRepository.findByCode("slDeptAssetAdmin");
        if (null == slDeptAssetAdminRole) {
            slDeptAssetAdminRole = new AuthRole();
            slDeptAssetAdminRole.setCode("slDeptAssetAdmin");
            slDeptAssetAdminRole.setName("部门资产管理员");
            this.authRoleRepository.save(slDeptAssetAdminRole);
        }

        // 部门资产负责人(省联社)
        AuthRole slDeptAssetPrincipalRole = this.authRoleRepository.findByCode("slDeptAssetPrincipal");
        if (null == slDeptAssetPrincipalRole) {
            slDeptAssetPrincipalRole = new AuthRole();
            slDeptAssetPrincipalRole.setCode("slDeptAssetPrincipal");
            slDeptAssetPrincipalRole.setName("部门资产负责人");
            this.authRoleRepository.save(slDeptAssetPrincipalRole);
        }

        // 资产归口管理员(省联社)
        AuthRole slAssetOwnerAdminRole = this.authRoleRepository.findByCode("slAssetOwnerAdmin");
        if (null == slAssetOwnerAdminRole) {
            slAssetOwnerAdminRole = new AuthRole();
            slAssetOwnerAdminRole.setCode("slAssetOwnerAdmin");
            slAssetOwnerAdminRole.setName("资产归口管理员");
            this.authRoleRepository.save(slAssetOwnerAdminRole);
        }

        // 资产归口负责人(省联社)
        AuthRole slAssetOwnerPrincipalRole = this.authRoleRepository.findByCode("slAssetOwnerPrincipal");
        if (null == slAssetOwnerPrincipalRole) {
            slAssetOwnerPrincipalRole = new AuthRole();
            slAssetOwnerPrincipalRole.setCode("slAssetOwnerPrincipal");
            slAssetOwnerPrincipalRole.setName("资产归口负责人");
            this.authRoleRepository.save(slAssetOwnerPrincipalRole);
        }

        // 人员
        AuthUser admin = this.authUserRepository.findByUsername("admin");
        if (null == admin) {
            admin = new AuthUser();
            admin.setUsername("admin");
            admin.setName("管理员");
            admin.setPassword(DigestUtils.md5DigestAsHex("123456".getBytes()));
            admin.setEnabled(true);
            admin.getOganizations().add(rootOrg);
            admin.getRoles().add(adminRole);
            this.authUserRepository.save(admin);
        }

        // 系统用户(科技公司)
        AuthUser systemUser = this.authUserRepository.findByUsername("systemUser");
        if (null == systemUser) {
            systemUser = new AuthUser();
            systemUser.setUsername("systemUser");
            systemUser.setName("系统用户-科技公司");
            systemUser.setPassword(DigestUtils.md5DigestAsHex("123456".getBytes()));
            systemUser.setEnabled(true);
            systemUser.getOganizations().add(resProOrg);
            systemUser.getRoles().add(systemUserRole);
            this.authUserRepository.save(systemUser);
        }

        // 部门资产专管员(科技公司)
        AuthUser kjDeptAssetAdmin = this.authUserRepository.findByUsername("kjDeptAssetAdmin");
        if (null == kjDeptAssetAdmin) {
            kjDeptAssetAdmin = new AuthUser();
            kjDeptAssetAdmin.setUsername("kjDeptAssetAdmin");
            kjDeptAssetAdmin.setName("部门资产专管员-科技公司");
            kjDeptAssetAdmin.setPassword(DigestUtils.md5DigestAsHex("123456".getBytes()));
            kjDeptAssetAdmin.setEnabled(true);
            kjDeptAssetAdmin.getOganizations().add(comprehensiveOrg);
            kjDeptAssetAdmin.getRoles().add(kjDeptAssetAdminRole);
            this.authUserRepository.save(kjDeptAssetAdmin);
        }

        // 部门负责人(科技公司)
        AuthUser kjDeptPrincipal = this.authUserRepository.findByUsername("kjDeptPrincipal");
        if (null == kjDeptPrincipal) {
            kjDeptPrincipal = new AuthUser();
            kjDeptPrincipal.setUsername("kjDeptPrincipal");
            kjDeptPrincipal.setName("部门负责人-科技公司");
            kjDeptPrincipal.setPassword(DigestUtils.md5DigestAsHex("123456".getBytes()));
            kjDeptPrincipal.setEnabled(true);
            kjDeptPrincipal.getOganizations().add(coreApplicationDevelopmentOrg);
            kjDeptPrincipal.getRoles().add(kjDeptPrincipalRole);
            this.authUserRepository.save(kjDeptPrincipal);
        }

        // 资产管理员(科技公司)
        AuthUser kjAssetAdmin = this.authUserRepository.findByUsername("kjAssetAdmin");
        if (null == kjAssetAdmin) {
            kjAssetAdmin = new AuthUser();
            kjAssetAdmin.setUsername("kjAssetAdmin");
            kjAssetAdmin.setName("资产管理员-科技公司");
            kjAssetAdmin.setPassword(DigestUtils.md5DigestAsHex("123456".getBytes()));
            kjAssetAdmin.setEnabled(true);
            kjAssetAdmin.getOganizations().add(scienceTechnologyOrg);
            kjAssetAdmin.getRoles().add(kjAssetAdminRole);
            this.authUserRepository.save(kjAssetAdmin);
        }

        // 综合管理部负责人(科技公司)
        AuthUser kjAdministrationPrincipal = this.authUserRepository.findByUsername("kjAdministrationPrincipal");
        if (null == kjAdministrationPrincipal) {
            kjAdministrationPrincipal = new AuthUser();
            kjAdministrationPrincipal.setUsername("kjAdministrationPrincipal");
            kjAdministrationPrincipal.setName("综合管理部负责人-科技公司");
            kjAdministrationPrincipal.setPassword(DigestUtils.md5DigestAsHex("123456".getBytes()));
            kjAdministrationPrincipal.setEnabled(true);
            kjAdministrationPrincipal.getOganizations().add(operationSupportOrg);
            kjAdministrationPrincipal.getRoles().add(kjAdministrationPrincipalRole);
            this.authUserRepository.save(kjAdministrationPrincipal);
        }

        // 资产采购员(省联社)
        AuthUser slAssetBuyer = this.authUserRepository.findByUsername("slAssetBuyer");
        if (null == slAssetBuyer) {
            slAssetBuyer = new AuthUser();
            slAssetBuyer.setUsername("slAssetBuyer");
            slAssetBuyer.setName("资产采购员-省联社");
            slAssetBuyer.setPassword(DigestUtils.md5DigestAsHex("123456".getBytes()));
            slAssetBuyer.setEnabled(true);
            slAssetBuyer.getOganizations().add(rootOrg);
            slAssetBuyer.getRoles().add(slAssetBuyerRole);
            this.authUserRepository.save(slAssetBuyer);
        }

        // 部门资产管理员(省联社)
        AuthUser slDeptAssetAdmin = this.authUserRepository.findByUsername("slDeptAssetAdmin");
        if (null == slDeptAssetAdmin) {
            slDeptAssetAdmin = new AuthUser();
            slDeptAssetAdmin.setUsername("slDeptAssetAdmin");
            slDeptAssetAdmin.setName("部门资产管理员-省联社");
            slDeptAssetAdmin.setPassword(DigestUtils.md5DigestAsHex("123456".getBytes()));
            slDeptAssetAdmin.setEnabled(true);
            slDeptAssetAdmin.getOganizations().add(hfAudit);
            slDeptAssetAdmin.getRoles().add(slDeptAssetAdminRole);
            this.authUserRepository.save(slDeptAssetAdmin);
        }

        // 部门资产负责人(省联社)
        AuthUser slDeptAssetPrincipal = this.authUserRepository.findByUsername("slDeptAssetPrincipal");
        if (null == slDeptAssetPrincipal) {
            slDeptAssetPrincipal = new AuthUser();
            slDeptAssetPrincipal.setUsername("slDeptAssetPrincipal");
            slDeptAssetPrincipal.setName("部门资产负责人-省联社");
            slDeptAssetPrincipal.setPassword(DigestUtils.md5DigestAsHex("123456".getBytes()));
            slDeptAssetPrincipal.setEnabled(true);
            slDeptAssetPrincipal.getOganizations().add(hr);
            slDeptAssetPrincipal.getRoles().add(slDeptAssetPrincipalRole);
            this.authUserRepository.save(slDeptAssetPrincipal);
        }

        // 资产归口管理员(省联社)
        AuthUser slAssetOwnerAdmin = this.authUserRepository.findByUsername("slAssetOwnerAdmin");
        if (null == slAssetOwnerAdmin) {
            slAssetOwnerAdmin = new AuthUser();
            slAssetOwnerAdmin.setUsername("slAssetOwnerAdmin");
            slAssetOwnerAdmin.setName("部门资产管理员-省联社");
            slAssetOwnerAdmin.setPassword(DigestUtils.md5DigestAsHex("123456".getBytes()));
            slAssetOwnerAdmin.setEnabled(true);
            slAssetOwnerAdmin.getOganizations().add(complianceRisk);
            slAssetOwnerAdmin.getRoles().add(slAssetOwnerAdminRole);
            this.authUserRepository.save(slAssetOwnerAdmin);
        }

        // 资产归口负责人(省联社)
        AuthUser slAssetOwnerPrincipal = this.authUserRepository.findByUsername("slAssetOwnerPrincipal");
        if (null == slAssetOwnerPrincipal) {
            slAssetOwnerPrincipal = new AuthUser();
            slAssetOwnerPrincipal.setUsername("slAssetOwnerPrincipal");
            slAssetOwnerPrincipal.setName("资产归口负责人-省联社");
            slAssetOwnerPrincipal.setPassword(DigestUtils.md5DigestAsHex("123456".getBytes()));
            slAssetOwnerPrincipal.setEnabled(true);
            slAssetOwnerPrincipal.getOganizations().add(business);
            slAssetOwnerPrincipal.getRoles().add(slAssetOwnerPrincipalRole);
            this.authUserRepository.save(slAssetOwnerPrincipal);
        }

    }

}
